#include"color_dialog.h"
ColorDialog::ColorDialog(QWidget *parent)
	:QDialog(parent)
 {
	this->setWindowTitle("颜色对话框示例");
    this->setMinimumWidth(300);
    whiteButton =new QPushButton("白色");
    connect(whiteButton, SIGNAL(clicked()), this, SLOT(start_white()));
    blackButton =new QPushButton("黑色");
    connect(blackButton, SIGNAL(clicked()), this, SLOT(start_black()));
    blueButton =new QPushButton("蓝色");
    connect(blackButton, SIGNAL(clicked()), this, SLOT(start_blue()));
    redButton=new QPushButton("红色");
    connect(redButton, SIGNAL(clicked()), this, SLOT(start_red()));

    frame =new QFrame();
    frame->setFrameShape(QFrame::Box);
    frame->setAutoFillBackground(true);
    frame->setMinimumHeight(50);

    mainLayout =new QGridLayout(this);
    mainLayout->addWidget(whiteButton,0,0);
    mainLayout->addWidget(blackButton,0,1);
    mainLayout->addWidget(blueButton,1,0);
    mainLayout->addWidget(redButton,1,1);
    mainLayout->addWidget(frame,2,0,1,2);
 }
 ColorDialog::~ColorDialog()
{
}
void ColorDialog::start_white() {
    QColor color =QColorDialog::getColor(Qt::white);
    if(color.isValid()){
        frame->setPalette(QPalette(color));
    }
}
void ColorDialog::start_black() {
    QColor color =QColorDialog::getColor(Qt::black);
    if(color.isValid()){
        frame->setPalette(QPalette(color));
    }
}
void ColorDialog::start_blue() {
    QColor color =QColorDialog::getColor(Qt::blue);
    if(color.isValid()){
        frame->setPalette(QPalette(color));
    }
}
void ColorDialog::start_red() {
    QColor color =QColorDialog::getColor(Qt::red);
    if(color.isValid()){
        frame->setPalette(QPalette(color));
    }
}